#ifndef _DB_MANAGER_H_
#define _DB_MANAGER_H_

#include "access/db.h"
#include "access/BufferManager.h"
#include "access/Transaction.h"

#include <map>
#include <pthread.h>
#include <string>

using namespace std;

class DatabaseManager
{
public:
    DatabaseManager(BufferManager* man);
    ~DatabaseManager();

    bool AddDatabase(const char* name, uint8_t column_count, KeyType type, Transaction* trans);
    
    Database* OpenDatabase(const char* name);
    
    bool CloseDatabase(Database* d);
    
    bool InsertRecord(void *db_pointer, Record *record, Transaction* trans);

    void PrintDatabase(void* db_pointer);
    
    static void CopyDatabaseManager(DatabaseManager* dest, DatabaseManager* source);

    pthread_mutex_t* LockPage();

private:
    //mutex for critical region
    pthread_mutex_t dman_mutex;

    // map for storage of database handles
    map<string,Database*> dbArray;
    
    // System buffer manager
    BufferManager* bm;
};

#endif
